package com.itheima08;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Xiao
 * @date 2021/7/13
 */
public class ExceptionDemo03 {
    /**
     * 异常处理
     *      try…catch…
     *      throws
     */
    public static void main(String[] args) {
        System.out.println("开始：");
//        method();
        try {
            method2();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println("结束。");
    }
    //运行时异常
    public static void method() throws ArrayIndexOutOfBoundsException {
            int[] arr = {0, 1, 2};
            System.out.println(arr[3]);
    }
    //编译时异常
    public static void method2 () throws ParseException {
        String s = "2018-08-08";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf.parse(s);
        System.out.println(date);
    }
}
